package com.xinghuo.building.ui.component.mine

import androidx.databinding.ObservableField
import com.xinghuo.building.data.database.AppDataBase
import com.xinghuo.building.data.database.Student
import com.xinghuo.building.data.database.StudentDao
import com.xinghuo.building.ui.base.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

/**
 * desc   : 模版
 * author : chendaning
 * date   : 7/4/21
 */
@HiltViewModel
class MineViewModel @Inject constructor(): BaseViewModel() {
//    private var mUserBean = MutableLiveData<UserBean>()
//    val bean: LiveData<UserBean> get() = mUserBean
    var mUserBean: UserBean = UserBean(ObservableField("jet33"), ObservableField(4), ObservableField("djid@gmail.com55"))

    fun loadData() {
        mUserBean.name.set("jack")
        mUserBean.age.set(90)
        mUserBean.email.set("jack@gmail.com")
    }

    fun getName(): String{
        return "boy"
    }

    fun showName(): Unit {

    }

    fun insertData(){
        val sDao: StudentDao = AppDataBase.instance.getStudentDao()

        var student1 = Student(null, "java", 1,"java@qq.com", 3)
        var student2 = Student(null, "c++", 2,"c++@qq.com", 3)
        var student3 = Student(null, "python", 3,"python@qq.com", 3)

        var sList: MutableList<Student> = mutableListOf<Student>()

        sList.add(student1)
        sList.add(student2)
        sList.add(student3)
        sDao.insertAll(sList)
        println("插入成功")

    }

    fun queryData(){
        val sDao: StudentDao = AppDataBase.instance.getStudentDao()
        var student = sDao.getAllStudents()
        println("=========size=" + student.size)
    }


}